/*
package com.example.springbootmybatis.commons.aop;

import com.example.springbootmybatis.commons.authrization.TokenManager;
import com.example.springbootmybatis.commons.jwt.JwtHelper;
import com.example.springbootmybatis.commons.tools.*;
import com.example.springbootmybatis.service.ITAuditlogsService;
import com.example.springbootmybatis.vo.JsonResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;


@Aspect
@Component
public class AuditLogAspect {
    //注入service,用来将日志信息保存在数据库
    @Resource()
    private ITAuditlogsService logservice;
    @Autowired
    private TokenManager tokenManager;

    @Autowired
    private JwtHelper jwtHelper;

    @Value("${OneMinuteActionAllowedTimes}")
    private String OneMinuteActionAllowedTimes;

    //配置接入点,如果不知道怎么配置,可以百度一下规则
    @Pointcut("(execution(* com.example.springbootmybatis.controller..*.*(..))&& (@annotation(org.springframework.web.bind.annotation.RequestMapping)))")
    private void controllerAspect() {
    }//定义一个切入点

    @Around("controllerAspect()")
    public Object execute(ProceedingJoinPoint pjp) throws Throwable {

        //获取登录用户账户
        String token = WebContextUtil.getRequest().getHeader(
                Constants.HEADER_STRING);
        var userIdAndSign = jwtHelper.getJwtTokenUserIdAndSign(token);
        String userId = "";
        String sign = "";
        if (userIdAndSign != null) {
            userId = userIdAndSign.get("userId");
            sign = userIdAndSign.get("sign");
        }

        //获取系统时间
        String time = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(new Date());
        //获取系统ip,
        String ip = NetworkUtil.getIpAddress(WebContextUtil.getRequest());

        //方法通知前获取时间,为什么要记录这个时间呢？当然是用来计算模块执行时间的
        long start = System.currentTimeMillis();
        // 拦截的实体类，就是当前正在执行的controller
        Object target = pjp.getTarget();
        // 拦截的方法名称。当前正在执行的方法
        String methodName = pjp.getSignature().getName();
        // 拦截的方法参数
        Object[] args = pjp.getArgs();
        JsonUtil.Object2String(args);
        System.out.println(Arrays.toString(args));
        String allowedGet = OneMinuteActionAllowedTimes;
        int alreadyActionCount = tokenManager.GetActionCount(target.getClass().getName() + methodName, sign);
        if (alreadyActionCount < Integer.parseInt(allowedGet)) {
            if (!StringUtil.isEmpty(sign)) {
                tokenManager.SetActionCount(target.getClass().getName() + methodName,sign);
            }
            var auditLog = new TAuditlogs
                    (
                            userId,
                            target.getClass().getName(),
                            methodName,
                            JsonUtil.Object2String(args),
                            time,
                            ip,
                            WebContextUtil.getRequest().getHeader("user-agent"),
                            ""
                    );
            logservice.save(auditLog);
            return pjp.proceed();

        } else {

            var auditLogDto = new TAuditlogs
                    (
                            userId,
                            target.getClass().getName(),
                            methodName,
                            JsonUtil.Object2String(args),
                            time,
                            ip,
                            WebContextUtil.getRequest().getHeader("user-agent"),
                            "警告：频繁访问被拒绝"
                    );
            logservice.save(auditLogDto);
            return new JsonResult(HttpStatus.FORBIDDEN, "警告：频繁访问被拒绝", null);
        }
    }
}*/
